import { Callout } from 'nextra-theme-docs';

Thanks for wanting to contribute! That means a lot to us. You can contribute in many ways, with or without any coding required.

If you encounter any issues, you can join [our Discord](https://discord.lagon.dev/) so we can help you.

<Callout type="info">
  Need some good first issues to start with? Check out the [good first issue
  label](https://github.com/lagonapp/lagon/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) on GitHub!
</Callout>

## Non-code contributions

### Issues and community help

Work in progress...

### Documentation website

The documentation website is made of [Markdown](https://en.wikipedia.org/wiki/Markdown) files, located in `packages/docs/pages/`. It uses [Nextra](https://nextra.vercel.app/) behind the scenes.

If you want to preview your changes, you can run the documentation website locally. First, follow the [Requirements](#requirements), and then run `pnpm start:docs` at the root of the project. You can now access the documentation website on `localhost:3000`.

## Code contributions

### Coding guidelines

- Commits are following the [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) convention.
- We use ESLint and Prettier to format our code, which should be handled automatically by most editors. If this is not the case, you can run the `lint` script.
- Make sure to add a test when adding new features / fixing bugs, so we can prevent any other future bugs.

### Requirements

You will need [Node.js](https://nodejs.org/en/) >= 16 and [PNPM](https://pnpm.io/) >= 7 (as of writing). You will also need [Docker](https://www.docker.com/) installed, and if you want to contribute to any Rust code, you will need [Rust](https://www.rust-lang.org/) >= 1.67 installed.

1. Fork and clone the repository
2. Install all NPM dependencies: `pnpm install`

If you want to contribute to the Dashboard / Serverless / CLI:

3. Run the local docker-compose: `docker-compose up -d`

4. Copy `packages/dashboard/.env.example` to `packages/dashboard/.env`, and `crates/serverless/.env.example` to `crates/serverless/.env`

5. Fill in the following environment variables:

##### In `packages/dashboard/.env` and `crates/serverless/.env`:

- (optional) `AXIOM_ORG_ID`, `AXIOM_TOKEN` to send and get logs to Axiom

##### In `packages/dashboard/.env`:

- `NEXTAUTH_SECRET` is a random secret for [NextAuth.js](https://authjs.dev/getting-started/oauth-tutorial#adding-environment-variables). Generate one using `$ openssl rand -base64 32`
- (optional) `GITHUB_CLIENT_ID`, `GITHUB_CLIENT_SECRET` are GitHub OAuth credentials. [Create a GitHub OAuth App](https://github.com/settings/developers)
- (optional) `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET` are Google OAuth credentials. [Create a Google OAuth App](https://console.developers.google.com/apis/credentials)
- (optional) `SMTP_HOST`, `SMTP_PORT`, `SMTP_USER`, `SMTP_PASSWORD`, `SMTP_FROM` are SMTP credentials to send emails

#### www

Navigate to `www` and run `pnpm dev` to start the website.

#### UI

Navigate to `packages/ui` and run `pnpm dev` to start the Storybook server.

#### Dashboard

Navigate to `packages/dashboard` and run `pnpm prisma migrate dev` to generate the database tables. You can now start the dashboard using `pnpm dev`.

#### JS Runtime

Navigate to `packages/js-runtime` and run `pnpm build` to build the JavaScript runtime. You can also run `pnpm dev` to watch for changes and automatically rebuild.

#### Serverless

Make sure you've followed the [Requirements](#requirements) and the [JS Runtime](#js-runtime) setup.

Navigate to `crates/serverless` and run `cargo run` to start the Serverless process. You can also run `cargo test` at the root of the project to run all tests.

#### CLI

Make sure you've followed the [Requirements](#requirements) and the [JS Runtime](#js-runtime) setup.

Navigate to `crates/cli` and run `cargo run` to start the CLI. You can pass arguments to the CLI using `cargo run -- <args>`. For example, `cargo run -- dev index.ts`.

#### WPT Runner

Make sure you've followed the [Requirements](#requirements) and the [JS Runtime](#js-runtime) setup.

First, you'll need to update the WPT submodule. Navigate to `tools/wpt` and run `git submodule update --init`.

Then, navigate to `crates/wpt-runner` and run `cargo run` to start the WPT Runner. You can optionally pass a path to a specific file or directory to run the tests on. For example, `cargo run -- ../../tools/wpt/fetch/api/headers/header-setcookie.any.js`

Every time you update the js-runtime code, you will need to rebuild it. We recommend running the `dev` script of js-runtime to watch for changes and automatically rebuild.

### Before submitting a PR

We have some checks in place to ensure we don't introduce bugs or regressions in PRs. You can run `pnpm lint` and `pnpm typecheck` at the project's root to ensure there are no lint and type errors.

Finally, run `pnpm changeset` to generate a [changeset file](https://github.com/changesets/changesets#how-do-we-do-that). Select the modified packages and choose the SemVer increment "major", "minor", or "patch", then write a short description of the changes.
